<?php
/**
 * ApictureController
 * 
 * @author
 * @version 
 */
require_once 'Zend/Controller/Action.php';
class ApictureController extends Zend_Controller_Action
{
    protected $_pictureModel;
	
	public function init()
	{
	     $authService = new Eleven_Service_Authentication();
	           
	    if ($authService->getIdentity()->role != 'Teacher') {
	        $this->_helper->redirector('index','index');
	    }
	    
		$this->_pictureModel = new Eleven_Model_Picture();
		$this->view->controller = $this->_request->controller;
	}
	
    /**
     * The default action - show the home page
     */
    public function indexAction ()
    {    
        $pictures = $this->_pictureModel->getPictures(null, $this->_getParam ( 'page', 1 ), array ('id DESC' ));
        $this->view->assign(array('pictures'=>$pictures));
    }
    
    public function deleteAction()
    {
        //Zend_Debug::dump($this->_request->getPost());
        $deleteInfo = $this->_request->getPost();
        
        foreach ($deleteInfo['deleteIds'] as $key => $val)
        {
            //Zend_Debug::dump($this->_pictureModel->getPictureById($key)->filename);   
            unlink($this->_pictureModel->getPictureById($key)->filename);
            unlink($this->_pictureModel->getPictureById($key)->thumb);
            
            $pic = $this->_pictureModel->deletePictureById($key);
        }
        
        return $this->_helper->redirector('index');
    }
}

